﻿Module ResourceAdministrator

    Public Sub insert(ByVal firstname As String, ByVal surname As String, ByVal documentType As Integer, ByVal document As String, ByVal email As String, ByVal hourCost As String)
        Dim cost As Decimal = convertStringToDecimal(hourCost)
        ResourceDao.insert(firstname, surname, documentType, document, email, COST)
    End Sub

    Public Sub update(ByVal id As Integer, ByVal firstname As String, ByVal surname As String, ByVal documentType As Integer, ByVal document As String, ByVal email As String, ByVal hourCost As String)
        Dim cost As Decimal = convertStringToDecimal(hourCost)
        ResourceDao.update(id, firstname, surname, documentType, document, email, cost)
    End Sub

    Public Function search() As Data.DataTable
        Return GenericDao.searchData("RESOURCES", "id, firstname, surname, email, create_date, hour_cost")
    End Function

    Public Function searchDataByFilter(ByVal id As String, ByVal firstname As String, ByVal surname As String, ByVal document_type As Integer, ByVal document_number As Integer) As Data.DataTable

        Return ResourceDao.searchDataByFilter("RESOURCES", id, firstname, surname, document_type, document_number)
    End Function

    Public Sub deleteById(ByVal id As Integer)
        GenericDao.deleteById("RESOURCES", id)
    End Sub

    Private Function convertStringToDecimal(ByVal stringValue As String) As Decimal
        Dim decimalValue As Decimal
        If stringValue.Equals("") Then
            decimalValue = 0
        Else
            decimalValue = CType(stringValue, Decimal)
        End If
        Return decimalValue
    End Function
End Module
